import { Column, CreateDateColumn, Entity, Index, PrimaryColumn, UpdateDateColumn } from 'typeorm';
import { Transform } from 'class-transformer';

@Entity()
export class FileStorage {

    @PrimaryColumn({nullable: false, unique: true})
    md5!: string;

    @Index()
    @Column({nullable: false})
    extname: string;

    @Column({type: 'bigint', nullable: false})
    size: number;

    @Column({nullable: false})
    filepath: string;

    @Column({type: 'timestamp', nullable: false})
    @Transform(params => params.value.valueOf())
    fileCreateTime: Date;

    @Column({type: 'timestamp', nullable: false})
    @Transform(params => params.value.valueOf())
    fileModifyTime: Date;

    @UpdateDateColumn()
    @Transform(params => params.value.valueOf())
    updateDate: Date;

    @CreateDateColumn()
    @Transform(params => params.value.valueOf())
    createDate: Date;

    @Column({default: false})
    isDeleted: boolean;
}
